package com.zeratul.satoken.demo.permission;

import com.zeratul.common.satoken.domain.entity.base.LoginUserAdapter;
import com.zeratul.common.satoken.handler.StpInterfaceCacheAdapter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 权限处理
 */
@Slf4j
@Component
public class MyStpInterfaceImpl extends StpInterfaceCacheAdapter {

    /**
     * 获取当前登录用户的权限码集合
     *
     */
    @Override
    public List<String> getPermissionList(LoginUserAdapter loginUser) {
        log.info("获取权限：{}", loginUser);
        return switch (loginUser.getUserId()) {
            case "10010" -> List.of("user:query", "user:add", "user:update");
            case "10011" -> List.of("user:query", "user:add");
            default -> List.of("user:query");
        };
    }

    /**
     * 获取当前登录用户的的角色标识集合
     */
    @Override
    public List<String> getRoleList(LoginUserAdapter loginUser) {
        log.info("获取角色：{}", loginUser);
        return switch (loginUser.getUserId()) {
            case "10010" -> List.of("admin");
            case "10011" -> List.of("normal");
            default -> List.of();
        };
    }
}
